package com.china.produce.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2023/4/23
 */
@Component
@Slf4j
public class KafkaConsumerListener {

    @KafkaListener(topics = "example",  containerFactory = "batchFactory")
    public void onMessage(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
        System.out.println("+++---");
        records.forEach(record -> {
            //log.info("size {} 消费消息2 topic {} partition {} value {}", records.size(), record.topic(), record.partition(), record.value());
        });

        ack.acknowledge();
    }

//    @KafkaListener(topics = "test.kafka.ack3", containerFactory = "batchFactory")
//    public void onMessage3(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
//
//        records.forEach(record -> {
//            log.info("消费消息3 topic {} partition {} value {}", record.topic(), record.partition(), record.value());
//        });
//
//        ack.acknowledge();
//    }
}
